package com.lanou3g.ptp.sign;

import com.lanou3g.ptp.sign.job.SignJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.PostConstruct;

@SpringBootApplication
@ComponentScan(lazyInit = true)
public class PtpSignServiceApplication {
    @Autowired
    private Scheduler scheduler;

    public static void main(String[] args) {
        SpringApplication.run(PtpSignServiceApplication.class, args);
    }

    @PostConstruct
    public void post() throws SchedulerException {
        String signJobClassName = SignJob.class.getName();
        scheduler.start();
        JobDetail taskJob = JobBuilder.newJob(SignJob.class).withIdentity(signJobClassName).build();
        CronScheduleBuilder schedule8h0m =
                CronScheduleBuilder.dailyAtHourAndMinute(8, 0).withMisfireHandlingInstructionDoNothing();
        Trigger trigger =
                TriggerBuilder.newTrigger().withIdentity(signJobClassName).withSchedule(schedule8h0m).build();
        scheduler.scheduleJob(taskJob, trigger);
    }
}
